package com.sloth.bear.controller;

import com.sloth.bear.dto.request.NavbarRequest;
import com.sloth.bear.dto.request.NavbarSortUpdateRequest;
import com.sloth.bear.dto.vo.NavbarDetailsVo;
import com.sloth.bear.dto.vo.NavbarListVo;
import com.sloth.bear.service.NavbarService;
import lombok.RequiredArgsConstructor;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 导航栏控制器
 */
@RestController
@RequestMapping("/navbar")
@RequiredArgsConstructor
public class NavbarController {

    private final NavbarService navbarService;

    /**
     * 创建导航
     */
    @PostMapping
    public NavbarDetailsVo createNavbar(@RequestBody @Valid NavbarRequest request) {
        return navbarService.createNavbar(request);
    }

    /**
     * 获取导航列表
     */
    @GetMapping("/list")
    public List<NavbarListVo> listNavbar() {
        return navbarService.listNavbar();
    }

    /**
     * 获取导航详情
     */
    @GetMapping("/{id}")
    public NavbarDetailsVo detailsNavbar(@PathVariable Long id) {
        return navbarService.detailsNavbar(id);
    }

    /**
     * 更新导航栏项目
     */
    @PutMapping("/{id}")
    public NavbarDetailsVo updateNavbar(@PathVariable Long id, @RequestBody @Valid NavbarRequest request) {
        return navbarService.updateNavbar(id, request);
    }

    /**
     * 删除导航栏项目
     */
    @DeleteMapping("/{id}")
    public Boolean deleteNavbar(@PathVariable Long id) {
        return navbarService.deleteNavbar(id);
    }
    
    /**
     * 批量更新导航栏排序
     */
    @PutMapping("/sort")
    public Boolean updateNavbarSort(@RequestBody @Valid NavbarSortUpdateRequest request) {
        return navbarService.updateNavbarSort(request);
    }
}